#include <iostream>


#include "DTD_Document.h"

using namespace std;

DTD_Document::DTD_Document()
{
	elements = new vector<DTD_Element *>;
}

DTD_Document::~DTD_Document()
{
	// Suppression des elements du vecteur d'elements.
    while(!elements->empty())
    {
        delete elements->back();
        elements->pop_back();
    }

    delete elements;
}

void DTD_Document::addElement( DTD_Element * element )
{
	elements->push_back( element );
}

void DTD_Document::addAttributes( string element_name, vector<DTD_Attribut *> * attributes )
{
	for ( vector<DTD_Element *>::iterator it = elements->begin() ; it != elements->end() ; it++ )
	{
		if ( (*it)->getName() == element_name )
		{
			(*it)->addAttributes( attributes );
		}
	}
}

string DTD_Document::toString(){
	string R;

	R = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
	for (unsigned int i = 0; i < this->elements->size(); i++)
	{
	    R += this->elements->at(i)->toString();
	    R += "\n";
	}

	string T;
	if(this->elements->empty())
	{
		T = "0";
	}
	else
	{
		T = "+";
	}

	return " Nb elements : " + T + " \n " + R;
}


//DTD_Document::~DTD_Document()
//{
//	// TODO Supprimer tout ces putains de vecteurs.
//}

//vector<DTD_Element*> DTD_Document::getElementList()
//{
//	return this->elementList;
//}
//
//

//
//void DTD_Document::addElement(DTD_Element* element){
//	this->elementList.push_back(element);
//}
//
//
//
//void DTD_Document::setElementList(vector<DTD_Element*> elementList)
//{
//	this->elementList = elementList;
//}
